package com.haixiaoke.saas.order.state.server;

import com.haixiaoke.saas.common.enums.OrderStateEnum;
import com.haixiaoke.saas.order.domain.Order;
import com.haixiaoke.saas.order.state.role.*;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.HashMap;
import java.util.Map;

/**
 * 状态服务方-实现类
 *
 * @author qixi
 * @date 2024-3-28 09:28:16
 */
public class OrderStateServerRole implements IOrderStateServerRole {

    private static final Logger LOG = LoggerFactory.getLogger(OrderStateServerRole.class);

    private final Map<String, ISpecificOrderStateServerRole> specificOrderStateServerRoleMap = new HashMap<>();
    private final Order order;


    public OrderStateServerRole(Order order) {
        LOG.info("状态服务方：OrderStateServerRole，初始化特定状态服务方对象");
        this.order = order;
        SignOrderOrderStateServerRole signOrderOrderStateServerRole = new SignOrderOrderStateServerRole(this);
        specificOrderStateServerRoleMap.put(OrderStateEnum.ORDER_STATE_TO_BE_SIGNED.getValue(), signOrderOrderStateServerRole);
        specificOrderStateServerRoleMap.put(OrderStateEnum.ORDER_STATE_SIGNED_CHECK.getValue(), signOrderOrderStateServerRole);
        specificOrderStateServerRoleMap.put(OrderStateEnum.ORDER_STATE_SIGNED.getValue(), new SignedOrderOrderStateServerRole(this));
        specificOrderStateServerRoleMap.put(OrderStateEnum.ORDER_STATE_RELET_AUDIT.getValue(), new ReletOrderOrderStateServerRole(this));
        specificOrderStateServerRoleMap.put(OrderStateEnum.ORDER_STATE_CHANGE_ROOM_AUDIT.getValue(), new ExchangeHouseOrderOrderStateServerRole(this));
        specificOrderStateServerRoleMap.put(OrderStateEnum.ORDER_STATE_SUBLET_AUDIT.getValue(), new SubleaseOrderOrderStateServerRole(this));
        specificOrderStateServerRoleMap.put(OrderStateEnum.ORDER_STATE_REFUND_RENT_AUDIT.getValue(), new RefundRentOrderOrderStateServerRole(this));
        specificOrderStateServerRoleMap.put(OrderStateEnum.ORDER_STATE_OVERTIME_REFUND_RENT.getValue(), new RefundRentOrderOrderStateServerRole(this));
        specificOrderStateServerRoleMap.put(OrderStateEnum.ORDER_STATE_REFUND_RENT.getValue(), new RefundRentOrderOrderStateServerRole(this));
        specificOrderStateServerRoleMap.put(OrderStateEnum.ORDER_STATE_OBLIGATION.getValue(), new PayOrderOrderStateServerRole(this));
        specificOrderStateServerRoleMap.put(OrderStateEnum.ORDER_STATE_RELET_OBLIGATION.getValue(), new PayReletOrderOrderStateServerRole(this));
        specificOrderStateServerRoleMap.put(OrderStateEnum.ORDER_STATE_STAY_CHECK_IN.getValue(), new StayCheckInOrderStateServerRole(this));
        specificOrderStateServerRoleMap.put(OrderStateEnum.ORDER_STATE_UNSUBSCRIBING.getValue(), new UnsubscribingOrderStateServerRole(this));
        specificOrderStateServerRoleMap.put(OrderStateEnum.ORDER_STATE_CHECK_IN.getValue(), new CheckInOrderStateServerRole(this));
        specificOrderStateServerRoleMap.put(OrderStateEnum.ORDER_STATE_CHECKING_OUT.getValue(), new CheckingOutOrderStateServerRole(this));
        specificOrderStateServerRoleMap.put(OrderStateEnum.ORDER_STATE_RELET_HAVE_PAID.getValue(), new ReletPaidOrderOrderStateServerRole(this));


    }

    private ISpecificOrderStateServerRole getSpecificStateServer() {
        LOG.info("状态服务方：OrderStateServerRole，根据状态获取相应的特定状态服务方对象");
        return specificOrderStateServerRoleMap.get(order.getOrderState());
    }


    public void pay() {
        ISpecificOrderStateServerRole specificStateServerRole = getSpecificStateServer();
        specificStateServerRole.pay(order);
    }


    @Override
    public void sign() {
        ISpecificOrderStateServerRole specificStateServerRole = getSpecificStateServer();
        specificStateServerRole.sign(order);
    }

    @Override
    public void signAudit() {
        ISpecificOrderStateServerRole specificStateServerRole = getSpecificStateServer();
        specificStateServerRole.signAudit(order);
    }

    @Override
    public void approved() {
        ISpecificOrderStateServerRole specificStateServerRole = getSpecificStateServer();
        specificStateServerRole.approved(order);
    }

    @Override
    public void disagree() {
        ISpecificOrderStateServerRole specificStateServerRole = getSpecificStateServer();
        specificStateServerRole.disagree(order);
    }

    @Override
    public void changeOrder() {
        ISpecificOrderStateServerRole specificStateServerRole = getSpecificStateServer();
        specificStateServerRole.changeOrder(order);
    }

    @Override
    public void cancel() {
        ISpecificOrderStateServerRole specificStateServerRole = getSpecificStateServer();
        specificStateServerRole.cancel(order);
    }

    @Override
    public void refundRent() {
        ISpecificOrderStateServerRole specificStateServerRole = getSpecificStateServer();
        specificStateServerRole.refundRent(order);
    }

    @Override
    public void refundRentAudit() {
        ISpecificOrderStateServerRole specificStateServerRole = getSpecificStateServer();
        specificStateServerRole.refundRentAudit(order);
    }

    @Override
    public void relet() {
        ISpecificOrderStateServerRole specificStateServerRole = getSpecificStateServer();
        specificStateServerRole.relet(order);
    }

    @Override
    public void reletAudit() {
        ISpecificOrderStateServerRole specificStateServerRole = getSpecificStateServer();
        specificStateServerRole.reletAudit(order);
    }

    @Override
    public void exchangeHouse() {
        ISpecificOrderStateServerRole specificStateServerRole = getSpecificStateServer();
        specificStateServerRole.exchangeHouse(order);
    }

    @Override
    public void exchangeHouseAudit() {
        ISpecificOrderStateServerRole specificStateServerRole = getSpecificStateServer();
        specificStateServerRole.exchangeHouseAudit(order);
    }

    @Override
    public void sublease() {
        ISpecificOrderStateServerRole specificStateServerRole = getSpecificStateServer();
        specificStateServerRole.sublease(order);
    }

    @Override
    public void subleaseAudit() {
        ISpecificOrderStateServerRole specificStateServerRole = getSpecificStateServer();
        specificStateServerRole.subleaseAudit(order);
    }

    @Override
    public void houseInspection() {
        ISpecificOrderStateServerRole specificStateServerRole = getSpecificStateServer();
        specificStateServerRole.houseInspection(order);
    }

    @Override
    public void orderOvertime() {
        ISpecificOrderStateServerRole specificStateServerRole = getSpecificStateServer();
        specificStateServerRole.orderOvertime(order);
    }

    @Override
    public void preOrderSignOvertime() {
        ISpecificOrderStateServerRole specificStateServerRole = getSpecificStateServer();
        specificStateServerRole.preOrderSignOvertime(order);
    }

    @Override
    public int orderStayCheckIn(String remark) {
        ISpecificOrderStateServerRole specificStateServerRole = getSpecificStateServer();
        return specificStateServerRole.orderStayCheckIn(order,remark);
    }

    @Override
    public int orderCancellation(String recordSource,String recordReason) {
        ISpecificOrderStateServerRole specificStateServerRole = getSpecificStateServer();
        return specificStateServerRole.orderCancellation(order,recordSource,recordReason);
    }

    @Override
    public int cancelReservation(String recordSource, String recordReason) {
        ISpecificOrderStateServerRole specificStateServerRole = getSpecificStateServer();
        return specificStateServerRole.cancelReservation(order,recordSource,recordReason);
    }

    @Override
    public int orderCheckIn(String recordSource, Long userId) {
        ISpecificOrderStateServerRole specificStateServerRole = getSpecificStateServer();
        return specificStateServerRole.orderCheckIn(order,recordSource,userId);
    }

    @Override
    public int unsubscribeSuccessfully(String recordSource, String recordReason) {
        ISpecificOrderStateServerRole specificStateServerRole = getSpecificStateServer();
        return specificStateServerRole.unsubscribeSuccessfully(order,recordSource,recordReason);
    }

    @Override
    public int unsubscribeFailureStayCheckIn(String remark) {
        ISpecificOrderStateServerRole specificStateServerRole = getSpecificStateServer();
        return specificStateServerRole.unsubscribeFailureStayCheckIn(order,remark);
    }

    @Override
    public int orderCheckingOut(String recordSource, Long operatorId) {
        ISpecificOrderStateServerRole specificStateServerRole = getSpecificStateServer();
        return specificStateServerRole.orderCheckingOut(order,recordSource,operatorId);
    }

    @Override
    public int orderCompletion(String recordSource, Long operatorId) {
        ISpecificOrderStateServerRole specificStateServerRole = getSpecificStateServer();
        return specificStateServerRole.orderCompletion(order,recordSource,operatorId);
    }
}
